#-*- coding: utf-8 -*-
#
# Copyright (C) 2007 Ville Leskinen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

from PyQt4 import QtCore, QtGui

#from qigcreator import QigCreator

class ImageViewer(QtGui.QMainWindow):
	def __init__(self, parent=None):
		QtGui.QMainWindow.__init__(self, parent)

		self.titleBegin = 'QigCreator - Image viewer'
		self.setWindowTitle(self.titleBegin)
		self.resize(640, 480)

		self._initActions()
		self._initGUI()

	def _initActions(self):
		pass

	def _initGUI(self):
		self.lblImage = QtGui.QLabel()
		self.lblImage.setBackgroundRole(QtGui.QPalette.Dark)

		self.saImage = QtGui.QScrollArea(self)
		self.saImage.setWidget(self.lblImage)
		self.saImage.setBackgroundRole(QtGui.QPalette.Dark)
		self.saImage.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)

		self.setCentralWidget(self.saImage)

	def openImage(self, lwiImage):
		filename = lwiImage.text()

		if filename:
			image = QtGui.QImage(filename)
			self.lblImage.setPixmap(QtGui.QPixmap.fromImage(image))
			self.lblImage.resize(self.lblImage.pixmap().size())
			self.setWindowTitle(self.titleBegin + '- %s' % (filename))
